﻿using System.Collections.Generic;
using NUnit.Framework;

namespace ViewModelMapper.Tests
{
    public class FlatViewModelFlatModelTests
    {
        #region CopyFrom
        [Test]
        public void TestCopyFrom_Int_0()
        {
            // arrange
            var model = new Model { ModelInt = 0 };
            var viewModel = new ViewModel { ViewModelInt = 1 };

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.ViewModelInt, Is.EqualTo(0));
        }

        [Test]
        public void TestCopyFrom_Int_Non0()
        {
            // arrange
            var model = new Model { ModelInt = 1 };
            var viewModel = new ViewModel { ViewModelInt = 0 };

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.ViewModelInt, Is.EqualTo(1));
        }

        [Test]
        public void TestCopyFrom_Bool_True()
        {
            // arrange
            var model = new Model { ModelBool = true };
            var viewModel = new ViewModel { ViewModelBool = false };

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.ViewModelBool, Is.EqualTo(true));
        }

        [Test]
        public void TestCopyFrom_Bool_False()
        {
            // arrange
            var model = new Model { ModelBool = false };
            var viewModel = new ViewModel { ViewModelBool = true };

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.ViewModelBool, Is.EqualTo(false));
        }

        [Test]
        public void TestCopyFrom_String_Null()
        {
            // arrange
            var model = new Model { ModelString = null };
            var viewModel = new ViewModel { ViewModelString = "Test" };

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.ViewModelString, Is.EqualTo(null));
        }

        [Test]
        public void TestCopyFrom_String_Empty()
        {
            // arrange
            var model = new Model { ModelString = string.Empty };
            var viewModel = new ViewModel { ViewModelString = "Test" };

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.ViewModelString, Is.EqualTo(string.Empty));
        }

        [Test]
        public void TestCopyFrom_String_Populated()
        {
            // arrange
            var model = new Model { ModelString = "NewValue" };
            var viewModel = new ViewModel { ViewModelString = "Test" };

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.ViewModelString, Is.EqualTo("NewValue"));
        }

        [Test]
        public void TestCopyFrom_Expression()
        {
            // arrange
            var model = new Model { ModelBool = true };
            var viewModel = new ViewModel();

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.PropertyFromExpression, Is.EqualTo("true"));
        }
        
        [Test]
        public void TestCopyFrom_Method()
        {
            // arrange
            var model = new Model { ModelInt = 5 };
            var viewModel = new ViewModel();

            // act
            viewModel.CopyFrom(model);

            // assert
            Assert.That(viewModel.PropertyFromMethod, Is.EqualTo(15));
        }
        #endregion

        #region CopyTo
        public void TestCopyTo_Int_0()
        {
            var model = new Model();
            var viewModel = new ViewModel();
        }

        public void TestCopyTo_Int_Non0()
        {
            var model = new Model();
            var viewModel = new ViewModel();
        }

        public void TestCopyTo_Bool_True()
        {

        }

        public void TestCopyTo_Bool_False()
        {

        }


        [Test]
        public void TestCopyTo_String_Null()
        {
           
        }

        [Test]
        public void TestCopyTo_String_Empty()
        {
          
        }

        [Test]
        public void TestCopyTo_String_Populated()
        {
           
        }
        #endregion

        #region Test Classes
        public class ViewModel : MappedViewModel<ViewModel, Model>
        {
            public int ViewModelInt { get; set; }
            public bool ViewModelBool { get; set; }
            public string ViewModelString { get; set; }

            public string PropertyFromExpression { get; set; }
            public int PropertyFromMethod { get; set; }

            public override IEnumerable<Map<ViewModel, Model>> Mappings()
            {
                yield return Map(vm => vm.ViewModelInt).ToAndFrom(m => m.ModelInt);
                yield return Map(vm => vm.ViewModelBool).ToAndFrom(m => m.ModelBool);
                yield return Map(vm => vm.ViewModelString).ToAndFrom(m => m.ModelString);
                yield return Map(vm => vm.PropertyFromExpression).From(m => m.ModelBool ? "true" : "false");
                yield return Map(vm => vm.PropertyFromMethod).From(m => IntMultiple(m.ModelInt, 3));
            }

            public int IntMultiple(int value, int multiplier)
            {
                return multiplier * value;
            }
        }

        public class Model
        {
            public int ModelInt { get; set; }
            public bool ModelBool { get; set; }
            public string ModelString { get; set; }
        }
        #endregion
    }
}
